﻿#include "AF_Layout.h"

namespace AF
{
	Layout::Layout()
	{
	}

	Layout::~Layout()
	{
	}

	Pointer Layout::Foreach(bool isFirst)
	{
		static Graphics** s_ppGraphics;
		s_ppGraphics = (Graphics**)m_lnkGraphicses.Foreach(isFirst);

		if(s_ppGraphics == NULL)
			return NULL;
		else
			return (Pointer)*s_ppGraphics;
	}

	UINT Layout::GetCount()
	{
		return m_lnkGraphicses.GetCount();
	}

	bool Layout::Init(Bundle* pArg)
	{
		return OnInit(pArg);
	}

	void Layout::Destroy()
	{
		m_lnkGraphicses.Clean();
		m_tabGraphicses.Clean();

		OnDestroy();
	}

	AF_CGraphics* Layout::GetGraphicsByName(_STRING strGraphicsName, int nParam1, int nParam2)
	{
		return GetGraphics(strGraphicsName);
	}

	void Layout::AddGraphics(Graphics* pGraphics)
	{
		AF_CHECK(pGraphics != NULL);

		// 检查并记录关键内容
		CheckGraphics(pGraphics);

		// 添加到队列
		m_lnkGraphicses.Add(pGraphics);
	}

	Graphics* Layout::GetGraphics(_STRING strGraphicsName)
	{
		return m_tabGraphicses.Get(strGraphicsName);
	}

	void Layout::CheckGraphics(Graphics* pGraphics)
	{
		static _STRING s_strGraphicsName;

		s_strGraphicsName = pGraphics->GetGraphicsName();
		if(s_strGraphicsName != "")
		{
			if(m_tabGraphicses.Find(s_strGraphicsName) < 0)
			{
				m_tabGraphicses.Put(s_strGraphicsName, pGraphics);
			}
		}

		FOREACH_P(Graphics, _pG, pGraphics)
		{
			CheckGraphics(_pG);
		}
	}
}